package implicits

import scala.collection.immutable.SeqMap
import implicits.Implicits._

/**
 * Created by Administrator on 2019/9/12
 */
trait MyMapsTool {

  implicit class MySeqMaps(maps: List[SeqMap[String, String]]) {

    def csvLines = {
      val headers = maps.head.keyList
      val lines = maps.map(_.valueList)
      headers :: lines
    }

  }

  implicit class ListMySeqMaps(mapsList: List[List[SeqMap[String, String]]]) {

    val emptyMaps = List[SeqMap[String, String]]()

    def myReduceLeft = {
      val nonEmptyMapsList = mapsList.filter(_.nonEmpty)
      if (nonEmptyMapsList.nonEmpty) {
        nonEmptyMapsList.reduceLeft { (x, y) =>
          x.zip(y).map { case (t, q) =>
            t ++ q
          }
        }
      } else emptyMaps
    }


  }


}
